package com.zr.paymentInformation.service.impl;

import com.zr.paymentInformation.mapper.PaymentInformationMapper;
import com.zr.paymentInformation.pojo.PaymentInformation;
import com.zr.paymentInformation.pojo.PaymentInformationAddVo;
import com.zr.paymentInformation.service.PaymentInformationService;
import com.zr.util.ResultBuildVo;
import com.zr.util.ResultVo;
import com.zr.util.ResultVOBuilder;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * Created by Administrator on 2019/7/3 0003.
 */
@Service
public class PaymentInformationServiceImpl implements PaymentInformationService{
    @Autowired
    private PaymentInformationMapper paymentInformationMapper;

    /**
     *
     *分期缴费申请信息的添加
     */
    @Override
    public ResultVo installmentApply(PaymentInformationAddVo paymentInformationAddVo,HttpServletRequest request) {
        //给数据库中的创建时间和修改时间等信息赋值
             Integer id= (Integer) request.getSession().getAttribute("loginId");
            if(id==null){
            return ResultBuildVo.error("请重新登陆","500");
        }

            PaymentInformation paymentInformation = new PaymentInformation();
            Date nowDate = new Date();
            paymentInformation.setCreateTime(nowDate);
            paymentInformation.setCreateName("小明");
            paymentInformation.setUpdateTime(nowDate);
            paymentInformation.setUpdateName("小明");
            BeanUtils.copyProperties(paymentInformationAddVo,paymentInformation);


        paymentInformationMapper.installmentApply(paymentInformation);
        return ResultVOBuilder.success(paymentInformationAddVo);
    }

    @Override
    public ResultVo queryById(Integer id) {
        PaymentInformationAddVo paymentInformationAddVo = paymentInformationMapper.queryById(id);
        if(id==null){
            return ResultBuildVo.error("请重新登陆","500");
        }
        return ResultVOBuilder.success(paymentInformationAddVo);
    }

}
